package com.css.ztb.service.impl;

import com.css.ztb.domain.SysRole;
import com.css.ztb.mapper.SysRoleMapper;
import com.css.ztb.service.RoleService;
import com.css.ztb.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author shipeilei
 * @date 2020-7-1 09:51:46
 * @desc desc
 */

@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    private SysRoleMapper sysRoleMapper;

    @Override
    public Set<String> selectRoleKeys(Long userId) {
        Set<String> roleSet = new HashSet<>();
        List<SysRole> roleList = sysRoleMapper.selectRolesByUserId(userId);
        for (SysRole sysRole : roleList) {
            if (StringUtils.isNotNull(sysRole)) {
                roleSet.addAll(Arrays.asList(sysRole.getRoleKey().trim().split(",")));
            }
        }
        return roleSet;
    }
}
